﻿@using Weapsy.Domain.Languages
@using Weapsy.Domain.Pages
@model Weapsy.Reporting.Pages.PageAdminModel

<ul class="nav nav-tabs">
    <li class="active">
        <a href="#Details" data-toggle="tab">Details</a>
    </li>
    <li>
        <a href="#Permissions" data-toggle="tab">Permissions</a>
    </li>
    <li>
        <a href="#Advanced" data-toggle="tab">Advanced</a>
    </li>
</ul>

<div class="tab-content" style="margin:25px 0">
    <div id="Details" class="tab-pane active">
        <div class="form-group has-feedback">
            <label for="name" class="col-md-2 control-label">Name</label>
            <div class="col-md-4">
                <input id="originalName" type="hidden" value="@Model.Name" />
                <input id="name" name="name" type="text" class="form-control" placeholder="Enter Name" value="@Model.Name">
                <i class="form-control-feedback glyphicon"></i>
            </div>
            <div class="col-md-6 help-block">
                <label id="name-error" for="name" class="text-danger" style="display:none;"></label>
            </div>
        </div>

        <ul class="nav nav-tabs">
            <li class="active">
                <a href="#Default" data-toggle="tab">Default</a>
            </li>
            @foreach (var pageLocalisation in Model.PageLocalisations)
            {
                var status = pageLocalisation.LanguageStatus == LanguageStatus.Active ? "" : " *";
                <li>
                    <a href="#@pageLocalisation.LanguageName" data-toggle="tab">@pageLocalisation.LanguageName@status</a>
                </li>
            }
        </ul>

        <div class="tab-content" style="margin:25px 0 35px;">
            <div id="Default" class="tab-pane active">
                <div class="form-group has-feedback">
                    <label for="url" class="col-md-2 control-label">Url</label>
                    <div class="col-md-4">
                        <input id="originalUrl" type="hidden" value="@Model.Url" />
                        <input id="url" name="url" type="text" class="form-control" placeholder="Enter Url" value="@Model.Url">
                        <i class="form-control-feedback glyphicon"></i>
                    </div>
                    <div class="col-md-6 help-block">
                        <label id="url-error" for="url" class="text-danger" style="display:none;"></label>
                    </div>
                </div>

                <div class="form-group has-feedback">
                    <label for="title" class="col-md-2 control-label">Title</label>
                    <div class="col-md-4">
                        <input id="title" name="title" type="text" class="form-control validate-title" placeholder="Enter Title" value="@Model.Title">
                        <i class="form-control-feedback glyphicon"></i>
                    </div>
                    <div class="col-md-6 help-block">
                        <label id="title-error" for="title" class="text-danger" style="display:none;"></label>
                    </div>
                </div>

                <div class="form-group has-feedback">
                    <label for="metaDescription" class="col-md-2 control-label">Meta Description</label>
                    <div class="col-md-4">
                        <input id="metaDescription" name="metaDescription" type="text" class="form-control validate-meta-description" placeholder="Enter Meta Description" value="@Model.MetaDescription">
                        <i class="form-control-feedback glyphicon"></i>
                    </div>
                    <div class="col-md-6 help-block">
                        <label id="metaDescription-error" for="metaDescription" class="text-danger" style="display:none;"></label>
                    </div>
                </div>

                <div class="form-group has-feedback">
                    <label for="metaKeywords" class="col-md-2 control-label">Meta Keywords</label>
                    <div class="col-md-4">
                        <input id="metaKeywords" name="metaKeywords" type="text" class="form-control validate-meta-keywords" placeholder="Enter Meta Keywords" value="@Model.MetaKeywords">
                        <i class="form-control-feedback glyphicon"></i>
                    </div>
                    <div class="col-md-6 help-block">
                        <label id="metaKeywords-error" for="metaKeywords" class="text-danger" style="display:none;"></label>
                    </div>
                </div>
            </div>
            @for (int i = 0; i < Model.PageLocalisations.Count; i++)
            {
                <input asp-for="PageLocalisations[i].LanguageId" type="hidden" />
                <div id="@Model.PageLocalisations[i].LanguageName" class="tab-pane">
                    <div class="form-group has-feedback">
                        <label asp-for="PageLocalisations[i].Url" class="col-md-2 control-label">Url</label>
                        <div class="col-md-4">
                            <input asp-for="PageLocalisations[i].Url" class="form-control validate-localisation-url" placeholder="Enter Url" />
                            <i class="form-control-feedback glyphicon"></i>
                        </div>
                        <div class="col-md-6 help-block">
                            <span asp-validation-for="PageLocalisations[i].Url" class="text-danger"></span>
                        </div>
                    </div>

                    <div class="form-group has-feedback">
                        <label asp-for="PageLocalisations[i].Title" class="col-md-2 control-label">Title</label>
                        <div class="col-md-4">
                            <input asp-for="PageLocalisations[i].Title" class="form-control validate-title" placeholder="Enter Title" />
                            <i class="form-control-feedback glyphicon"></i>
                        </div>
                        <div class="col-md-6 help-block">
                            <span asp-validation-for="PageLocalisations[i].Title" class="text-danger"></span>
                        </div>
                    </div>

                    <div class="form-group has-feedback">
                        <label asp-for="PageLocalisations[i].MetaDescription" class="col-md-2 control-label">Meta Description</label>
                        <div class="col-md-4">
                            <input asp-for="PageLocalisations[i].MetaDescription" class="form-control validate-meta-description" placeholder="Enter Meta Description" />
                            <i class="form-control-feedback glyphicon"></i>
                        </div>
                        <div class="col-md-6 help-block">
                            <span asp-validation-for="PageLocalisations[i].MetaDescription" class="text-danger"></span>
                        </div>
                    </div>

                    <div class="form-group has-feedback">
                        <label asp-for="PageLocalisations[i].MetaKeywords" class="col-md-2 control-label">Meta Keywords</label>
                        <div class="col-md-4">
                            <input asp-for="PageLocalisations[i].MetaKeywords" class="form-control validate-meta-keywords" placeholder="Enter Meta Keywords" />
                            <i class="form-control-feedback glyphicon"></i>
                        </div>
                        <div class="col-md-6 help-block">
                            <span asp-validation-for="PageLocalisations[i].MetaKeywords" class="text-danger"></span>
                        </div>
                    </div>
                </div>
            }
        </div>
        @if (Model.PageLocalisations.Any(x => x.LanguageStatus != LanguageStatus.Active))
        {
            <span style="font-style: italic;">* Language Not Active</span>
        }
    </div>
    <div id="Permissions" class="tab-pane">
        <div class="form-group has-feedback">
            <div class="col-md-12">
                <table class="table table-bordered" style="width:auto;">
                    <tr>
                        <th>Role</th>
                        @for (int i = 0; i < Enum.GetValues(typeof(PermissionType)).Length; i++)
                        {
                            <th class="text-center">@Enum.GetValues(typeof(PermissionType)).GetValue(i)</th>
                        }  
                    </tr>
                    @for (int i = 0; i < Model.PagePermissions.Count; i++)
                    {
                        <tr>
                            <td>
                                @Model.PagePermissions[i].RoleName&nbsp;
                                <input asp-for="PagePermissions[i].RoleId" type="hidden" />
                                <input asp-for="PagePermissions[i].Disabled" type="hidden" />
                            </td>
                            @for (int j = 0; j < Model.PagePermissions[i].PagePermissionTypes.Count; j++)
                            {
                                <td class="text-center">
                                    <input asp-for="PagePermissions[i].PagePermissionTypes[j].Type" type="hidden" />
                                    @if (Model.PagePermissions[i].Disabled)
                                    {
                                        <input asp-for="PagePermissions[i].PagePermissionTypes[j].Selected" type="checkbox" disabled="disabled" />
                                    }
                                    else
                                    {
                                        <input asp-for="PagePermissions[i].PagePermissionTypes[j].Selected" type="checkbox" />
                                    }                                    
                                </td>
                            }
                        </tr>
                    }
                </table>
            </div>
        </div>
    </div>
    <div id="Advanced" class="tab-pane">
        @if (Model.Id == Guid.Empty)
        {
            <div class="form-group has-feedback">
                <div class="col-md-12">
                    <table class="table table-bordered" style="width: auto;">
                        <tr>
                            <th>Menu</th>
                            <th class="text-center">Add Item</th>
                        </tr>
                        @for (int i = 0; i < Model.Menus.Count; i++)
                        {
                            <tr>
                                <td>
                                    @Model.Menus[i].MenuName&nbsp;
                                    <input asp-for="Menus[i].MenuId" type="hidden" />
                                </td>
                                <td class="text-center">
                                    <input asp-for="Menus[i].Selected" type="checkbox" />
                                </td>
                            </tr>
                        }
                    </table>
                </div>
            </div>
        }
    </div>
</div>